#!/bin/bash

cat << "EOF"
================================================
    配置 Docker 镜像加速器
================================================
EOF

echo ""
echo "📝 Docker Desktop 的配置文件位置："
echo "   ~/Library/Group Containers/group.com.docker/settings.json"
echo ""
echo "🔧 请按照以下步骤手动配置："
echo ""
echo "1️⃣  打开 Docker Desktop"
echo "2️⃣  点击右上角 ⚙️  (Settings)"
echo "3️⃣  选择左侧 'Docker Engine'"
echo "4️⃣  在 JSON 配置中找到或添加 'registry-mirrors' 字段："
echo ""
cat << 'JSON'
{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "registry-mirrors": [
    "https://docker.m.daocloud.io",
    "https://dockerproxy.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://docker.nju.edu.cn"
  ]
}
JSON
echo ""
echo "5️⃣  点击 'Apply & Restart' 按钮"
echo "6️⃣  等待 Docker 重启完成（约 30 秒）"
echo ""
echo "✅ 配置完成后，重新运行 docker-启动.command"
echo ""
echo "================================================"
echo "可用的国内镜像源："
echo "================================================"
echo "- DaoCloud:   https://docker.m.daocloud.io"
echo "- DockerProxy: https://dockerproxy.com"
echo "- 中科大:      https://docker.mirrors.ustc.edu.cn"
echo "- 南京大学:    https://docker.nju.edu.cn"
echo "================================================"
echo ""
echo "💡 提示：如果某个镜像源失效，可以只保留可用的"
echo ""

# 检测当前配置
echo "🔍 正在检查当前 Docker 配置..."
if docker info 2>/dev/null | grep -A 5 "Registry Mirrors:" | grep -q "http"; then
    echo ""
    echo "✓ 当前已配置的镜像源："
    docker info 2>/dev/null | grep -A 10 "Registry Mirrors:"
else
    echo ""
    echo "⚠️  当前未配置镜像加速器"
fi

echo ""
echo "按 Enter 键关闭此窗口..."
read

